from manimlib import *
# 文字实例
class TextExample(Scene):
    def construct(self):
      # self.embed()
      text = Text("Here is a text", font = "Consolas", font_size = 90)
      difference = Text("""
        The most important difference between Text and TexText is that\n
        you can change the font more easily, but can't use the LaTeX grammar
        """, font="Arial", font_size = 24,
        # t2c是一个由 文本-颜色 键值对组成的字典
        t2c = {"Text": BLUE, "TexText": BLUE, "LaTeX": ORANGE}
      )
      VGroup(text, difference).arrange(DOWN, buff = 1)
      self.play(Write(text))
      self.play(FadeIn(difference, UP))
      self.wait()

      fonts = Text(
        "And you can also set the font according to different words",
        font="Arial",
        # t2f 由 文本-字体 键值对组成的字典
        t2f={"font": "Consolas", "words": "Consolas"},
        # t2c 由 文本-颜色 键值对组成的字典
        t2c={"font": BLUE, "words": GREEN}
      )
      fonts.set_width(FRAME_WIDTH - 1)
      slant = Text(
        "And the same as slant and weight",
        font="Consolas",
        # t2s 由 文本 - 文字样式 键值对组成的字典
        t2s={"slant": ITALIC},
        # t2w 由 文本 - 文字宽度 键值对组成的字典
        t2w={"weight": BOLD},
        t2c={"slant": ORANGE, "weight": RED}
      )
      # VGroup 将 多个 VMobject 看成一个整体， arrange 将其中子物体依次向下排列，且间距为 buff
      VGroup(fonts, slant).arrange(DOWN, buff=0.8)
      # FadeIn 将物体淡入，第一个参 淡入的 VMobject 第二个参 shift 数表示淡入方向。
      self.play(FadeOut(text), FadeOut(difference, shift=DOWN))
      # Write 显示书写效果的动画
      self.play(Write(fonts))
      self.wait()
      self.play(Write(slant))
      self.wait()

